/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package babyroom

import javafx.event._
import javafx.scene._
import javafx.scene.control._
import javafx.scene.paint._
import javafx.stage._

class SFX {

}

class ButtonBuilder(private val button: Button = new Button) extends Builder[Button]{
  def text(str: String): ButtonBuilder = {
    button.textProperty.set(str)
    this
  }
  
  def onAction(action: ActionEvent => Unit): ButtonBuilder = {
    import EventLambdar._
    button.onActionProperty.set(action)
    this
  }
  
  def build: Button = button
}

object ButtonBuilder{
  implicit def toBuilder(button: Button): ButtonBuilder = new ButtonBuilder(button)
}

class SceneBuilder(private val scene: Scene) extends Builder[Scene]{
  def fill(paint: Paint): SceneBuilder = {
    scene.fillProperty.set(paint)
    this
  }
  
  def build: Scene = scene
}

object SceneBuilder{
  implicit def toBuilder(scene: Scene): SceneBuilder = new SceneBuilder(scene)
}

class StageBuilder(private val stage: Stage = new Stage) extends Builder[Stage]{
  def title(str: String): StageBuilder = {
    stage.titleProperty.set(str)
    this
  }
  
  def width(w: Double): StageBuilder = {
    stage.setWidth(w)
    this
  }
  
  def height(h: Double): StageBuilder = {
    stage.setHeight(h)
    this
  }
  
  def build: Stage = stage
} 

object StageBuilder{
  implicit def toBuild(stage: Stage): StageBuilder = new StageBuilder(stage)
}

trait Builder[T]{
  def build: T
}

object Builder{
  implicit def build[T](builder: Builder[T]): T = builder.build
}

object EventLambdar{
  implicit def toHandler[T <: Event](l: T => Unit): EventHandler[T] = new EventHandler[T](){
    def handle(event: T): Unit = l(event)
  }
}